/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import cheat.entities.keys.AssignmentExternalUrlPK;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * Holds the external URL metadata associated with the assignment.
 *
 * @author Keith Shie
 */
@Entity
@IdClass( AssignmentExternalUrlPK.class )
@Table(name = "asgn_ext_url")
@NamedQueries({@NamedQuery(name = "AssignmentExternalUrl.findAll", query = "SELECT a FROM AssignmentExternalUrl a"),
        @NamedQuery(name = "AssignmentExternalUrl.findByUuid", query =
        "SELECT a FROM AssignmentExternalUrl a WHERE a.uuid = :uuid"),
        @NamedQuery(name = "AssignmentExternalUrl.findByUrlId", query =
        "SELECT a FROM AssignmentExternalUrl a WHERE a.urlId = :urlId"),
        @NamedQuery(name = "AssignmentExternalUrl.findByUrl", query = "SELECT a FROM AssignmentExternalUrl a WHERE a.url = :url")})
public class AssignmentExternalUrl implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "uuid", nullable = false)
  private int uuid;
  @Id
  @Column(name = "url_id", nullable = false)
  @SequenceGenerator(name="url_seq", sequenceName="asgn_ext_url_url_id_seq", allocationSize=1)
  @GeneratedValue( strategy=GenerationType.SEQUENCE,generator="url_seq")
  private int urlId;
  @Basic(optional = false)
  @Column(name = "url", nullable = false, length = 256)
  private String url;
  @JoinColumns({@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable = false, insertable = false, updatable =
          false)})
  @ManyToOne(optional = false)
  private AssignmentProperty assignmentProperty;

  public AssignmentExternalUrl() {
  }

  public AssignmentExternalUrl(int uuid) {
    this.uuid = uuid;
  }

  public AssignmentExternalUrl(int uuid, int urlId) {
    this( uuid );
    this.urlId = urlId;
  }

  public AssignmentExternalUrl(int uuid, String url) {
    this( uuid );
    this.url = url;
  }

  public AssignmentExternalUrl(int uuid, int urlId, String url) {
    this( uuid, url );
    this.urlId = urlId;
  }

  public int getUrlId() {
    return urlId;
  }

  public void setUrlId(int urlId) {
    this.urlId = urlId;
  }

  public int getUuid() {
    return uuid;
  }

  public void setUuid(int uuid) {
    this.uuid = uuid;
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  public AssignmentProperty getAssignmentProperty() {
    return assignmentProperty;
  }

  public void setAssignmentProperty(AssignmentProperty assignmentProperty) {
    this.assignmentProperty = assignmentProperty;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) uuid;
    hash += (int) urlId;
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentExternalUrl)) {
      return false;
    }
    AssignmentExternalUrl other = (AssignmentExternalUrl) object;
    if (this.uuid != other.uuid) {
      return false;
    }
    if (this.urlId != other.urlId) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentExternalUrl[uuid=" + uuid + ", urlId=" + urlId + "]";
  }

}
